<template>
  <el-card shadow="hover">
    <el-form :model="formData" label-width="85px" :rules="formRules">
      <el-form-item label="平台" prop="name">
        <el-input v-model="formData.name" maxlength="50" show-word-limit clearable :disabled="true"/>
      </el-form-item>
      <el-form-item label="App_Id" prop="appId">
        <el-input v-model="formData.appId" maxlength="50" show-word-limit clearable/>
      </el-form-item>
      <el-form-item label="App_Secret" prop="appSecret">
        <el-input v-model="formData.appSecret" maxlength="50" show-word-limit clearable/>
      </el-form-item>
    </el-form>

    <el-button v-hasPermi="['yxt:sysShare:update']" type="primary" @click="submit">更 新</el-button>
    <el-button v-hasPermi="['yxt:sysShare:update']" type="primary" @click="resetForm">重 置</el-button>
  </el-card>
</template>

<script lang="ts" setup>
import {useSysShareApi} from "@/api/yxt/supplier/sysShare";
import {useMessage} from "@/hooks/web/useMessage";

defineOptions({name: 'YxtSysShare'})

const sysShareApi = useSysShareApi();
const message = useMessage();
const {t} = useI18n()
const formData = ref({
  id: undefined,
  name:'',
  appId:'',
  appSecret:''
})

const formRules = reactive({
  name: [{required: true, message: '推送配置名称不能为空', trigger: ['blur', 'change']}],
  appId: [{required: true, message: 'App_Id不能为空', trigger: ['blur', 'change']}],
  appSecret: [{required: true, message: 'App_Secret不能为空', trigger: ['blur', 'change']}],
})

const getDetail = async () => {
  formData.value = await sysShareApi.getSysShare() || {};
}

const submit = async () => {
  try {
    await message.confirm(t('common.updateMessage'));
    await sysShareApi.updateSysShare(formData.value);
    message.success(t('common.updateSuccess'));
    getDetail();
  } catch {
  }
}


const resetForm = () => {
  getDetail();
}

onMounted(() => {
  getDetail();
})
</script>

